package com.example.demo.service.impl;

import com.example.demo.service.MyService;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Collection;

/**
 * @author tds
 * @version 1.0.0
 * @Company
 * @ClassName MyServiceImpl
 * @Description TODO（这里用一句话描述这个类的作用)
 * @Date 2022-04-05 23:40
 */
@Service
public class MyServiceImpl implements MyService {

    @Override
    public boolean hasPerimit(HttpServletRequest request, Authentication authentication) {
        Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
        System.out.println("uri:" + request.getRequestURI());
        return authorities.contains(new SimpleGrantedAuthority(request.getRequestURI()));
    }
}
